package com.das.mechanic_base.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.utils.X3ScreenUtils;

/**
 * 作者：zhanglei on 2019-11-27 21:08
 * <p>
 * 邮箱：916256628@qq.com
 */
public class X3BottomCameraDialog extends PopupWindow implements View.OnClickListener {

    private Context context;
    View view;
    IOnClikPhotoListener iOnClikPhotoListener;

    ClickAlbumListener iOnClickAlbumListener;

    public X3BottomCameraDialog(Context context) {
        super(context);
        this.context = context;

        view = View.inflate(context, R.layout.x3_popu_camera, null);
        TextView tv_photo = view.findViewById(R.id.tv_photo);
        TextView tv_album = view.findViewById(R.id.tv_album);
        TextView tv_cancel = view.findViewById(R.id.tv_cancel);

        tv_photo.setOnClickListener(this);
        tv_album.setOnClickListener(this);
        tv_cancel.setOnClickListener(this);
        setContentView(view);
        this.setWidth(X3ScreenUtils.getScreenWidth(context) - X3ScreenUtils.dipToPx(22,context));
        //设置PopupWindow弹出窗体的高
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setOutsideTouchable(true);
        ColorDrawable dw = new ColorDrawable(0xffffff);
        setBackgroundDrawable(dw);
        this.setAnimationStyle(R.style.MyDialog);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_photo) {
            if (iOnClikPhotoListener != null) {
                iOnClikPhotoListener.clickPhoto();
            }
        } else if (id == R.id.tv_album) {
            if (iOnClickAlbumListener != null) {
                iOnClickAlbumListener.clickAlbum();
            }
        } else if (id == R.id.tv_cancel) {
            this.dismiss();
        }
    }

    public interface IOnClikPhotoListener {
        void clickPhoto();
    }

    public IOnClikPhotoListener getiOnClikPhotoListener() {
        return iOnClikPhotoListener;
    }

    public void setiOnClikPhotoListener(IOnClikPhotoListener iOnClikPhotoListener) {
        this.iOnClikPhotoListener = iOnClikPhotoListener;
    }

    public interface ClickAlbumListener {
        void clickAlbum();
    }

    public ClickAlbumListener getiOnClickAlbumListener() {
        return iOnClickAlbumListener;
    }

    public void setiOnClickAlbumListener(ClickAlbumListener iOnClickAlbumListener) {
        this.iOnClickAlbumListener = iOnClickAlbumListener;
    }
}
